module.exports = app => {
    const mongoose = app.mongoose;
    const Schema = mongoose.Schema;
    const ArticleSchema = new Schema({
        title: { // 标题
            type: String,
            required: true
        },
        author: { type: Schema.Types.ObjectId, ref: 'User' }, // 作者
        department: { // 部门
            type: String,
            required: true
        },
        content: String, // 正文
        status: { // 1 未发布 2 发布
            type: Number,
            default: 1
        },
        mode:  { // 1 EXE 2 通用
            type: Number,
            default: 0
        },
        blocks: { // 块
            type: String,
            required: true
        },
        summary: String, // 简介
        description: String, // 描述
        OAName: String, // 专栏号名称
        type: { // 类型 1 同事圈 2 知识库 3 专栏号
            type: Number,
            default: 0
        },
        cover: String, // 封面
        publishDate: Date, // 发布时间
    }, { timestamps: { createdAt: 'createDate', updatedAt: 'updateDate' } });
    ArticleSchema.pre('findOne', function () {
        this.populate('author', '_id name sex avatarUrl role');
    });
    ArticleSchema.pre('find', function () {
        this.populate('author', '_id name sex avatarUrl -role');
    });
    return mongoose.model('Article', ArticleSchema);
};